package com.shardingsphere.springbootshardingsphere.controller;

import com.alibaba.fastjson.JSONObject;
import com.shardingsphere.springbootshardingsphere.entity.User;
import com.shardingsphere.springbootshardingsphere.service.TestService;
import com.shardingsphere.springbootshardingsphere.vo.OrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;
import java.util.logging.Logger;

/**
 * @description:
 * @author: ZeckZheng
 * @time: 2023/10/23 23:39
 */
@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {
    Logger logger = Logger.getLogger("BusinessLog");
    Logger xxx = Logger.getLogger("XXXBusinessLog");

    @Autowired
    private TestService testService;

    @RequestMapping("/user")
    public Object test() {
        User user = new User();
        user.setId(new Random().nextLong());
        user.setUname("test");
        log.info(JSONObject.toJSONString(user));
        logger.info(JSONObject.toJSONString(user));
        xxx.info(JSONObject.toJSONString(user));
        return user;
    }

    @RequestMapping("/query")
    public User queryUser(Integer id) {
        return testService.queryUser(id);
    }

    @RequestMapping("/create/order")
    public void createOrder() {
        //testService.createOrder();
        //testService.createOrder1();
        testService.createOrder2();
    }

    @RequestMapping("/query/order/amount")
    public List<OrderVo> queryOderAmount() {
        return testService.queryOderAmount();
    }


}
